import React from 'react';
import {observer} from "mobx-react";
import { getAntd, getEcCom } from '../../util/convert';
import * as _ from '../../util/public/common';
import { loadFullResource } from '../../util/asyncLoad';
import ReqfileUpload from '../layout/ReqfileUpload';
const { WeaLocaleProvider } = getEcCom();


const getLabel = WeaLocaleProvider.getLabel;

@observer
class ReqWffileUpload extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            isComplete:false,
            loading: false,
			draggable: true,
            columns: [{
                title: <span>附件</span>,
                dataIndex: "filetext",
                com: [{
                    type: "TEXT",
                    key: "filetext",
                    className: "wea-table-editable-demo-html"
                }]
            },{
                title: <span>操作人</span>,
                dataIndex: "username",
                com: [{
                    type: "TEXT",
                    key: "username",
                    className: "wea-table-editable-demo-html"
                }]
            },{
                title: <span>时间</span>,
                dataIndex: "uploaddate",
                com: [{
                    type: "TEXT",
                    key: "uploaddate",
                    className: "wea-table-editable-demo-html"
                }]
            },{
                title: <span></span>,
                dataIndex: "filedownload",
                com: [{
                    type: "TEXT",
                    key: "filedownload",
                    className: "wea-table-editable-demo-html"
                }]
            }],
            initialDatas: [],
            datas: [],
            selectedRowKeys: [],
            cells: [{
                id: "2",
                checkbox: {
                    com: [{
                        type: "CHECKBOX",
                        key: "checkbox",
                        otherParams: { content: "otherParams.content" },
                        disabled: true
                    }]
                }
            }],
            showCopy: false,
            buttonsType: "inline",
            showRowSelect: true,
            pageSize: 0,
            operationKey: "canClick"
        }
    }

    componentWillMount = () =>{

        let that = this;
        let inteval = window.setInterval(function () {
            const ecCom = window.ecCom;
            if (!that.state.isComplete && ecCom.WeaTableEditable){
                that.setState({
                    isComplete: true
                })
            }else if(that.state.isComplete){
                clearInterval(inteval);
            }
        },200);

        const layoutStore = window.parent && window.parent.WfForm && window.parent.WfForm.getLayoutStore();
        const { fieldid } = this.getRequestParam();
        const fieldMark = `field${fieldid}`;
        const fieldObj = layoutStore.initFieldObj("", fieldMark);
        const viewAttr = this.getFieldCurViewAttr(fieldMark, fieldObj);
        let specialobj  = fieldObj.specialobj ? mobx.toJS(fieldObj.specialobj) : {};
        const { filedatas } = specialobj;

        let initialDatas = [];
        filedatas && filedatas.map(item =>{
            if(layoutStore.propFileCfg.files_link_onlyview === "1"){
                //formFieldId=${fieldid}&formFieldAttr=2 控制当前这个附件文档是否可编辑 后续需要修改为接口,临时处理
                item.filelink = `${item.filelink}&isEdit=1&formFieldId=${fieldid}&formFieldAttr=2`;
            }

            const { selectValueZ=-9 } = item;
            let selectName='';
            if(selectValueZ != -9){
                if(selectValueZ==0){
                    selectName='公开'
                }else if(selectValueZ==1){
                    selectName='内部';
                }else if(selectValueZ==2){
                    selectName='秘密';
                }else if (selectValueZ==3){
                    selectName='机密';
                }else if (selectValueZ==-1){
                    selectName='未定密级';
                }
            }

            initialDatas.push({
                id: item.fileid,
                filetext: `<a href=${item.filelink} target="_blank">${item.filename}</a>`,
                filedownload: `<a href=${item.loadlink} target="_blank">下载</a>`,
                uploaddate:item.uploaddate,
                username:item.username,
                selectName:selectName
            });
        });
        let title = [];
        if(viewAttr == 3 && initialDatas.length == 0){
            title = <span style={{ color: "red" }}>（必填）</span>;
        }
        let showAdd = true;
        let showDelete = true;
        if(viewAttr == 1){
            showAdd = false;
            showDelete = false;
        }
        this.setState({initialDatas: initialDatas, datas: initialDatas, title: title, showAdd: showAdd, showDelete: showDelete});

    }

    componentDidMount() {
        this.controlAsyncLoad();
    }

    componentDidUpdate(preProps) {
        this.controlAsyncLoad();
    }

    controlAsyncLoad(){
        //非Chrome下等首屏只读渲染完，再加载全量组件库
        window.__hasLoadFullResource__ !== true && loadFullResource();
    }

    fileChangeEvent = (ids,filedatas) => {
        const layoutStore = window.parent && window.parent.WfForm && window.parent.WfForm.getLayoutStore();
        const globalStore = window.parent && window.parent.WfForm && window.parent.WfForm.getGlobalStore();
        const { fieldid } = this.getRequestParam();
        const fieldMark = `field${fieldid}`;
        const fieldObj = layoutStore.initFieldObj("", fieldMark);
        const viewAttr = this.getFieldCurViewAttr(fieldMark, fieldObj);
        const specialobj = fieldObj.specialobj || {};

        if(specialobj.filedatas){
            filedatas && filedatas.map(item => {
                for(let i=0; i<specialobj.filedatas.length; i++){
                    let item2 = specialobj.filedatas[i];
                    if(item2.fileid == item.fileid){
                        item.selectValueZ = item2.selectValueZ;
                    }
                }
            });
        }
        let newfileids = [];
        filedatas && filedatas.map(item => {
            const { selectValueZ=-9 } = item;
            if(selectValueZ == -9){
                newfileids.push(item.fileid);
            }
        });

        specialobj.filedatas = filedatas;
        layoutStore.changeSingleFieldValue(fieldMark, {value:ids.join(","), specialobj:specialobj});
        let datas = [];

        let accSecretLevelParams = {"newfileids": newfileids.join(",")};
        globalStore.getAccSecretLevelForDocid(accSecretLevelParams).then(data => {
            filedatas && filedatas.map(item =>{

                if(layoutStore.propFileCfg.files_link_onlyview === "1"){
                    //formFieldId=${fieldid}&formFieldAttr=2 控制当前这个附件文档是否可编辑 后续需要修改为接口,临时处理
                    item.filelink = `${item.filelink}&isEdit=1&formFieldId=${fieldid}&formFieldAttr=2`;
                }

                if(data[item.fileid] != undefined){
                    item.selectValueZ = data[item.fileid];
                }

                const { selectValueZ=-9 } = item;
                let selectName='';
                if(selectValueZ != -9){
                    if(selectValueZ==0){
                        selectName='公开'
                    }else if(selectValueZ==1){
                        selectName='内部';
                    }else if(selectValueZ==2){
                        selectName='秘密';
                    }else if (selectValueZ==3){
                        selectName='机密';
                    }else if (selectValueZ==-1){
                        selectName='未定密级';
                    }
                }

                datas.push({id: item.fileid, filetext: `<a href=${item.filelink} target="_blank">${item.filename}</a>`
                    ,selectName:selectName,uploaddate:item.uploaddate,
                    username:item.username,});
            });

            let title = [];
            if(viewAttr == 3 && datas.length == 0){
                title = <span style={{ color: "red" }}>（必填）</span>;
            }
            this.setState({datas: datas, title: title});
        });

    }

    onUploading = (type) => {
        let valueInfo = null;
        const layoutStore = window.parent && window.parent.WfForm && window.parent.WfForm.getLayoutStore();
        const { fieldid } = this.getRequestParam();
        const fieldMark = `field${fieldid}`;
        const fieldObj = layoutStore.initFieldObj("", fieldMark);
        const fieldVars = {};
        //type = true 标记改字段值为空 type = false 标记该字段值不为空 这个时候不需要更新状态
        if(type == "false" && fieldObj.value == ""){
            valueInfo = {value:"-1"};
        }else if(type == "true"){
            valueInfo = {value:""};
        }
        if(type != "false" && type != "true"){
            const {variable = {}} = fieldObj;
            const {fileUploadStatus} = variable;
            if(fileUploadStatus != 'error') {
                fieldVars.fileUploadStatus = type;
            }
        }
        layoutStore.changeSingleFieldValue(fieldMark, valueInfo, fieldVars);
        this.setState({ loading: type === "uploading" })
    }

    render() {
        const { WeaUpload, WeaTableEditable } = getEcCom();
        const { Spin } = getAntd();
        const globalStore = window.parent && window.parent.WfForm && window.parent.WfForm.getGlobalStore();
        const layoutStore = window.parent && window.parent.WfForm && window.parent.WfForm.getLayoutStore();
        const { fieldid } = this.getRequestParam();
        const fieldMark = `field${fieldid}`;
        const { fieldAttrMap,variableMap } = layoutStore;
        const { JSComplete } = globalStore;
        const fieldAttr = fieldAttrMap.get(fieldid);
        const fieldObj = layoutStore.initFieldObj("", fieldMark);
        const viewAttr = this.getFieldCurViewAttr(fieldMark, fieldObj);
        let htmltype = fieldAttr.htmltype || 0;
        let detailtype = fieldAttr.detailtype || 0;
        //字段值,特殊字符转换
        const { value } = fieldObj;
        const fieldValue = this.restoreSpeicalChar(fieldid, value.toString(), htmltype, detailtype, viewAttr);
        const promptRequired = variableMap.get("promptRequiredField") === fieldMark;   //是否提示必填

        const baseProps = {JSComplete, fieldid, viewAttr, detailtype};
        baseProps.value = fieldValue;
        baseProps.fieldName  = fieldMark;
        baseProps.fieldlabel = fieldAttr.fieldlabel;
        baseProps.defaultFocus = promptRequired === true;
        if(htmltype === 6){  //附件字段特殊处理(标签页切换过程中需要render附件组件)
            //const fileVisible = judgeFieldExistVisibleArea(conf, fieldid);
            const fileVisible = true;
            baseProps.display = fileVisible;
        }
        baseProps.style={"display": "none"};

        const fieldName = fieldMark;
        const { fileattr } = fieldAttr;
        let specialobj  = fieldObj.specialobj ? mobx.toJS(fieldObj.specialobj) : {};
        const { filedatas,showBatchLoad } = specialobj;
        //计算附件上传目录  catelogType = 0:固定目录 1：选择目录
        let category = "";
        let errorMsg = "";
        let { catelogType,docCategory,selectedCateLog,maxUploadSize }  = fileattr;
        if(catelogType === 0){
            if(_.trim(docCategory).length > 0){
                category = _.trim(docCategory);
            }else{
                errorMsg = getLabel(83157,"附件上传目录未设置!");
            }
        }else{
            const selectedCatalog = this.getFileSelectedCatalog();
            if(selectedCatalog.errorMsg){
                errorMsg = selectedCatalog.errorMsg;
            }else{
                category = selectedCatalog && selectedCatalog.docCategory;
                maxUploadSize = selectedCatalog && selectedCatalog.maxUploadSize;
            }
        }
        const { commonParam } = globalStore;
        const { workflowid,requestid,authStr,authSignatureStr,f_weaver_belongto_userid,f_weaver_belongto_usertype,wfTestStr,isprint } = commonParam;
        const listType = detailtype === 2 ? "img" : "list";
        const urlParams  = `&authStr=${authStr}&authSignatureStr=${authSignatureStr}&f_weaver_belongto_userid=${f_weaver_belongto_userid}&f_weaver_belongto_usertype=${f_weaver_belongto_usertype}&wfTestStr=${wfTestStr}`;
        let uploadUrl = `/api/doc/upload/uploadFile2Doc?category=${category}&workflowid=${workflowid}&listType=${listType}${urlParams}`;
        baseProps.showBatchLoad = false;
        baseProps.showClearAll = 1;
        baseProps.uploadUrl = uploadUrl;
        baseProps.maxUploadSize = maxUploadSize;
        baseProps.category = category;
        filedatas && filedatas.map(item =>{
            if(viewAttr > 1 && layoutStore.propFileCfg.files_link_onlyview === "1"){
                //formFieldId=${fieldid}&formFieldAttr=2 控制当前这个附件文档是否可编辑 后续需要修改为接口,临时处理
                item.filelink = `${item.filelink}&isEdit=1&formFieldId=${fieldid}&formFieldAttr=2`;
            }
        });
        baseProps.datas = filedatas;
        baseProps.btnSize = "default";
        baseProps.autoUpload = 0;
        baseProps.listType = listType;
        baseProps.uploadId = fieldName;
        baseProps.errorMsg = errorMsg;
        // if(showBatchLoad){
        //     let batchLoadUrl  = `/weaver/weaver.file.FileDownload?fieldvalue=${value}&download=1&downloadBatch=1&desrequestid=0&requestid=${requestid}${urlParams}`;
        //     baseProps.batchLoadUrl = batchLoadUrl;
        // }
        //字段是否开启拖拽， 后台是否开启拖拽，文件是否可编辑
        const { issortable= true, isresetname = true,isshowclerarall = false,isautoupload = true} = fieldAttr;
        //是否显示清楚全部
        baseProps.showClearAll = false;
        baseProps.issortable = issortable;
        baseProps.editable = isresetname;
        baseProps.autoUpload = isautoupload;//自动上传
        if(isautoupload) {//自动上传则存为草稿 ,同时需要不丢失其他属性
            baseProps.uploadParams = {isFirstUploadFile : "9", ...baseProps.uploadParams};//流程草稿
        }

        if(fileattr.imgHeight===0){
            fileattr.imgHeight=50;
        }

        if(fileattr.imgWidth===0){
            fileattr.imgWidth=50;
        }

        return(
            <div>
            <div id="wf-fileupload" className="example">
                <WeaUpload ecId={`${this && this.props && this.props.ecId || ''}_WeaUpload@li5935`}
                    ref={fieldName}
                    uploadId={fieldName}
                    {...{...fileattr,...baseProps}}
                    needCalculateWidth={isprint != "1"}
                    onChange={this.fileChangeEvent}
                    onUploading={this.onUploading}
                    />
                {this.state.isComplete && <WeaTableEditable ecId={`${this && this.props && this.props.ecId || ''}_WeaTableEditable@zty2131`}
                    {...this.state}
                    operationKey={this.state.operationKey}
                    onRowSelect={this.onRowSelect}
                    willDelete={this.willDelete}
                    willAdd={this.willAdd}
                    onChange={this.onChange}
                    onDrop={this.onDrop}
                    />}
                {this.state.isComplete && <div style={{textAlign: "center"}}>
                    <Spin spinning={this.state.loading} size="large" />
                </div>}   
            </div>
            {ReqfileUpload && <ReqfileUpload/>}
            </div>
        )
    }
    //获取附件字段对应的选择框目录信息
    getFileSelectedCatalog(){
        const layoutStore = window.parent && window.parent.WfForm && window.parent.WfForm.getLayoutStore();
        const { fieldAttrMap } = layoutStore;
        const fieldAttr = fieldAttrMap.get(fieldid);
        const { fileattr } = fieldAttr || {};
        const selectedFieldid = fileattr.selectedCateLog;
        if(fileattr.catelogType !== 1 || !selectedFieldid || !fieldAttrMap.has(selectedFieldid))      //附件字段非选择框控制目录
            return {};

        const selectedFieldValue = this.getRelateFieldValue(selectedFieldid, rowIndex);
        const selectedFieldAttr = fieldAttrMap.get(selectedFieldid);
        const { fieldlabel,selectattr } = selectedFieldAttr;

        let selectedCatalog = {};
        if(selectedFieldid !== "" && selectedFieldValue !== ""){
            selectattr && selectattr.selectitemlist.map(v =>{
                if(v && v.selectvalue.toString() === selectedFieldValue.toString())
                    selectedCatalog = {docCategory:v.docCategory, maxUploadSize:v.maxUploadSize||5};
            });
        }else{
            selectedCatalog.errorMsg = `${getLabel(125389,'请先选择')}“${fieldlabel}”`;
        }
        return selectedCatalog;
    }

    willDelete = (datas, keys) =>
        new Promise((resolve, reject) => {
            const { Modal } = getAntd();
            const { confirm } = Modal;
            confirm({
                content: `确认删除选中附件吗? `,
                onOk: () => {
                    const layoutStore = window.parent && window.parent.WfForm && window.parent.WfForm.getLayoutStore();
                    const { fieldid } = this.getRequestParam();
                    const fieldMark = `field${fieldid}`;
                    const fieldObj = layoutStore.initFieldObj("", fieldMark);
                    const viewAttr = this.getFieldCurViewAttr(fieldMark, fieldObj);
                    const specialobj = fieldObj.specialobj || {};
                    let nextfiledatas = [];
                    let ids = [];
                    specialobj.filedatas && specialobj.filedatas.map(item => {
                        if(keys.indexOf(item.fileid) == -1){
                            nextfiledatas.push(item);
                            ids.push(item.fileid);
                        }
                    });
                    specialobj.filedatas = nextfiledatas;
                    layoutStore.changeSingleFieldValue(fieldMark, {value:ids.join(","), specialobj:specialobj});
                    let datas = [];
                    nextfiledatas && nextfiledatas.map(item =>{
                        if(layoutStore.propFileCfg.files_link_onlyview === "1"){
                            //formFieldId=${fieldid}&formFieldAttr=2 控制当前这个附件文档是否可编辑 后续需要修改为接口,临时处理
                            item.filelink = `${item.filelink}&isEdit=1&formFieldId=${fieldid}&formFieldAttr=2`;
                        }

                        const { selectValueZ=-9 } = item;
                        let selectName='';
                        if(selectValueZ != -9){
                            if(selectValueZ==0){
                                selectName='公开'
                            }else if(selectValueZ==1){
                                selectName='内部';
                            }else if(selectValueZ==2){
                                selectName='秘密';
                            }else if (selectValueZ==3){
                                selectName='机密';
                            }else if (selectValueZ==-1){
                                selectName='未定密级';
                            }
                        }

                        datas.push({id: item.fileid, filetext: `<a href=${item.filelink} target="_blank">${item.filename}</a>`
                            ,selectName:selectName,uploaddate:item.uploaddate,
                            username:item.username,});
                    });
                    let title = [];
                    if(viewAttr == 3 && datas.length == 0){
                        title = <span style={{ color: "red" }}>（必填）</span>;
                    }
                    this.setState({datas: datas, title:title});
                    resolve(false);
                },
                onCancel: () => resolve(false)
            });
        });

    willAdd = (datas, addData) =>
        new Promise((resolve, reject) => {
            $("#wf-fileupload").find(".wea-upload-container").find("button").click();
            resolve(false);
        });


    onRowSelect = selectedRowKeys => {
        this.setState({ selectedRowKeys });
    };

    onChange = changeDatas => {
        const layoutStore = window.parent && window.parent.WfForm && window.parent.WfForm.getLayoutStore();
        const { fieldid } = this.getRequestParam();
        const fieldMark = `field${fieldid}`;
        const fieldObj = layoutStore.initFieldObj("", fieldMark);
        const viewAttr = this.getFieldCurViewAttr(fieldMark, fieldObj);
        const specialobj = fieldObj.specialobj || {};
        let nextfiledatas = [];
        let ids = [];

        changeDatas.map(changeData => {
            specialobj.filedatas && specialobj.filedatas.map(item => {
                if (item.fileid == changeData.id){
                    nextfiledatas.push(item);
                    ids.push(item.fileid);
                }
            });
        });

        specialobj.filedatas = nextfiledatas;
        layoutStore.changeSingleFieldValue(fieldMark, {value:ids.join(","), specialobj:specialobj});
        let datas = [];
        nextfiledatas && nextfiledatas.map(item =>{
            if(layoutStore.propFileCfg.files_link_onlyview === "1"){
                //formFieldId=${fieldid}&formFieldAttr=2 控制当前这个附件文档是否可编辑 后续需要修改为接口,临时处理
                item.filelink = `${item.filelink}&isEdit=1&formFieldId=${fieldid}&formFieldAttr=2`;
            }

            const { selectValueZ=-9 } = item;
            let selectName='';
            if(selectValueZ != -9){
                if(selectValueZ==0){
                    selectName='公开'
                }else if(selectValueZ==1){
                    selectName='内部';
                }else if(selectValueZ==2){
                    selectName='秘密';
                }else if (selectValueZ==3){
                    selectName='机密';
                }else if (selectValueZ==-1){
                    selectName='未定密级';
                }
            }

            datas.push({id: item.fileid, filetext: `<a href=${item.filelink} target="_blank">${item.filename}</a>`
                ,selectName:selectName,uploaddate:item.uploaddate,
                username:item.username,});
        });
        let title = [];
        if(viewAttr == 3 && datas.length == 0){
            title = <span style={{ color: "red" }}>（必填）</span>;
        }
        this.setState({datas: datas, title:title});
    };

    //根据字段id取对应字段值
    getRelateFieldValue = (fieldid, rowIndex) =>{
        const fieldidArr = [fieldid];
        const relateFieldValues = this.getRelateFieldValues(fieldidArr, rowIndex);
        return relateFieldValues[fieldid] || "";
    }

    //根据字段id集合获取对应字段值
    getRelateFieldValues = (fieldidArr=[], rowIndex) =>{
        let result = {};
        const layoutStore = window.parent && window.parent.WfForm && window.parent.WfForm.getLayoutStore();
        const { mainData,detailMap,fieldAttrMap } = layoutStore;
        fieldidArr.map(fieldid =>{
            let fieldValue = "";
            if(fieldAttrMap.has(fieldid.toString())){
                const tableMark = fieldAttrMap.get(fieldid.toString()).tableMark;
                if(tableMark === "main"){
                    fieldValue = mainData.has(`field${fieldid}`) ? mainData.get(`field${fieldid}`).value : "";
                }else if(tableMark.indexOf("detail_") > -1){
                    const detailObj = detailMap.get(tableMark);
                    const detailData = detailObj.detailData;
                    fieldValue = detailData.has(`field${fieldid}_${rowIndex}`) ? detailData.get(`field${fieldid}_${rowIndex}`).value : "";
                }
            }
            result[fieldid] = fieldValue.toString();
        });
        return result;
    }

    //渲染组件时，字符还原成可显示DOM格式
    restoreSpeicalChar = (fieldid, str, htmltype, detailtype, viewAttr) =>{
        const globalStore = window.parent && window.parent.WfForm && window.parent.WfForm.getGlobalStore();
        const layoutStore = window.parent && window.parent.WfForm && window.parent.WfForm.getLayoutStore();
        if(viewAttr === 1 && ((htmltype === 1 && detailtype ===1) || (htmltype === 2 && detailtype ===1))){     //只读时字符转换成DOM结构
            //部分多行文本框由程序插入html源码，只读情况需显示转译后html内容
            if((htmltype === 1 || htmltype === 2) && detailtype === 1){
                const { isbill } = globalStore.commonParam;
                const { propFileCfg } = layoutStore;
                const fieldKey = `field${fieldid}_${isbill}`;
                const support_html_textarea_field = propFileCfg.support_html_textarea_field || "";
                if(support_html_textarea_field.indexOf(fieldKey) > -1){
                    str = str.replace(/\n/ig, "<br>");
                    return str;
                }
            }
            str = this.restoreSpeicalStr(str);
            //QC966924 统计解决E7升E9单行、多行文本框历史数据乱码问题
            str = str.replace(/&amp;#160;/g, '&nbsp;');
        }
        return str;
    }

    restoreSpeicalStr = (str) =>{
        str = str.toString();
        //需先转译
        str = str.replace(/&/ig, "&amp;");
        str = str.replace(/</ig, "&lt;");
        str = str.replace(/>/ig, "&gt;");
        //后转译
        str = str.replace(/\n/ig, "<br>");
        //优化断行，多个空格中首个空格不转译，其余空格转&nbsp;
        //str = str.replace(/ /ig, "&nbsp;");
        //破IE，这样写报错，不支持零宽断言
        //str = str.replace(/(?<= ) /ig,'&nbsp;');
        str = str.replace(/( {2,})/ig, val => " " + val.substring(1).replace(/ /ig,"&nbsp;"));
        str = str.replace(/\"/ig, "&quot;");
        return str;
    }

    //计算字段当前时刻的只读/必填属性
    getFieldCurViewAttr = (fieldMark, fieldObj) =>{
        const globalStore = window.parent && window.parent.WfForm && window.parent.WfForm.getGlobalStore();
        const layoutStore = window.parent && window.parent.WfForm && window.parent.WfForm.getLayoutStore();
        const { fieldAttrMap } = layoutStore;
        const { fieldid } = this.getRequestParam();
        const fieldAttr = fieldAttrMap.get(fieldid);
        if(fieldAttr == null)
            return 0;
        const { cellInfo,mainData,detailMap } = layoutStore;
        const tableMark = fieldAttr.tableMark;
        if(!fieldObj)
            fieldObj = layoutStore.initFieldObj("", fieldMark);

        const { variable } = fieldObj;
        let viewAttr = parseInt(fieldAttr.viewattr) || 0;     //后台设置的字段属性
        if(viewAttr === 0 && _.has(cellInfo, ["fieldCellInfo", fieldid]))    //字段放在模板上但未设置属性的默认给只读属性
            viewAttr = 1;
        if(fieldAttr.isonlyshow === 1)
            viewAttr = 1;
        if(variable.has("viewAttr")){    //显示属性联动改变的字段属性
            const changeViewAttr = parseInt(variable.get("viewAttr")) || 0;
            if(changeViewAttr === 1 || changeViewAttr === 2 || changeViewAttr === 3)
                viewAttr = changeViewAttr;
        }
        if(viewAttr === 2 || viewAttr === 3){
            const commonParam = globalStore.commonParam;
            //已办、提交确认置为只读，提交确认时位置字段需再获取一次，跟随原来的属性
            if(parseInt(commonParam.isviewonly || 0) === 1 || (parseInt(commonParam.isaffirmance || 0) === 1 && fieldObj.fieldType != '9-1'))
                viewAttr = 1;
        }
        return viewAttr;
    }

    getRequestParam = () => {
        let url = window.location + ""; //获取url中"?"符后的字串
        let theRequest = new Object();
        if (url.indexOf("?") != -1) {
            let urls = url.split("?");
            let str = urls[1];
            let strs = str.split("&");
            for(let i = 0; i < strs.length; i ++) {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
}

export default ReqWffileUpload
